##################################################################################
##                                                                              ##
##  This file is part of the buola project (https://code.google.com/p/buola/).  ##
##                                                                              ##
##  Copyright(c) 2007-2012 Xavi Gratal                                          ##
##  gratal AT gmail DOT com                                                     ##
##                                                                              ##
##  Buola is free software: you can redistribute it and/or modify               ##
##  it under the terms of the GNU General Public License as published by        ##
##  the Free Software Foundation, either version 3 of the License, or           ##
##  (at your option) any later version.                                         ##
##                                                                              ##
##  Buola is distributed in the hope that it will be useful,                    ##
##  but WITHOUT ANY WARRANTY; without even the implied warranty of              ##
##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               ##
##  GNU General Public License for more details.                                ##
##                                                                              ##
##  You should have received a copy of the GNU General Public License           ##
##  along with buola.  If not, see <http://www.gnu.org/licenses/>.              ##
##                                                                              ##
##################################################################################

if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
	set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif()

#this adds srcdir and builddir to the include path, which is good
set(CMAKE_INCLUDE_CURRENT_DIR ON)

#this puts include files in the source tree before the ones installed in the
#system, so that they are chosen in case of conflict
set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON)

#of course
set(CMAKE_COLOR_MAKEFILE ON)

#version to use for libraries
set(GENERIC_LIB_VERSION "0.0.1")
set(GENERIC_LIB_SOVERSION "0")

#default C and C++ flags (mostly about warnings)
set(COMMON_WARNINGS "-Wall -Wextra -Winit-self -Wpointer-arith -Wno-sign-compare -Wno-unused-parameter -Wcast-qual -Wno-uninitialized")
set(CPP_SPECIFIC_WARNINGS "-Wno-non-virtual-dtor -Woverloaded-virtual -Wsign-promo -Wstrict-aliasing=2")

if(BUOLA_WARNINGS_AS_ERRORS)
    set(COMMON_WARNINGS "${COMMON_WARNINGS} -Werror -Wno-error=deprecated-declarations")
endif()

set(CMAKE_CXX_FLAGS "-D_REENTRANT -fstrict-aliasing -march=nocona ${COMMON_WARNINGS} ${CPP_SPECIFIC_WARNINGS}")

if(BUOLA_PLATFORM_MAC)
    set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-isystem ")
    include_directories(/usr/X11/include)
    link_directories(/opt/local/lib)
    if(BUOLA_COMPILER_CLANG)
        include_directories(BEFORE SYSTEM /opt/local/include)
        #include_directories(BEFORE SYSTEM /opt/local/include/gcc48/c++ /opt/local/include/gcc48/c++/x86_64-apple-darwin13 /opt/local/include)
        #link_directories(/opt/local/lib/gcc48)
        #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -U__GNUC_MINOR__ -D__GNUC_MINOR__=7")
    endif()
endif()
if(BUOLA_COMPILER_CLANG)
    set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas -Wno-reserved-user-defined-literal -Wno-mismatched-tags")
    #the following should always be masked
#    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weverything -Wno-error -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-documentation-unknown-command -Wno-used-but-marked-unused")
    #these can be unmasked from time to time
#    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-weak-vtables")
elseif(BUOLA_COMPILER_GCC)
    set(CMAKE_CXX_FLAGS "-std=gnu++11 ${CMAKE_CXX_FLAGS} -D_GNU_SOURCE -pthread -Wno-unused-local-typedefs -Wdouble-promotion -Wzero-as-null-pointer-constant")
#    set(CMAKE_CXX_FLAGS "-std=gnu++1y -fdiagnostics-color=auto ${CMAKE_CXX_FLAGS} -D_GNU_SOURCE -pthread -Wno-unused-local-typedefs -Wdouble-promotion -Wzero-as-null-pointer-constant")
elseif(BUOLA_COMPILER_INTEL)
    set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS} -D_GNU_SOURCE -pthread -Wremarks -diag-disable 2304 -diag-disable 383 -diag-disable 444 -diag-disable 981 -diag-disable 1599 -diag-disable 2102 -diag-disable 161")
endif()

set(CMAKE_C_FLAGS "-march=nocona")

execute_process(COMMAND tput cols OUTPUT_VARIABLE BUOLA_TERM_COLUMNS)
if(NOT BUOLA_TERM_COLUMNS)
    set(BUOLA_TERM_COLUMNS 80)
endif()
